﻿//编辑对话框
var dlg = new MyAppDialog(600, 400);//关闭对话框
function closeDialog(reload) {
    dlg.close();

    if (reload)
        $("#datagrid").treegrid("reload");
}

var cols = [[
    { field: "Id", title: 'Id', width: 10, rowspan: 2, hidden: true },
    { field: "text", title: '科室名称', rowspan: 2, sortable: false, width: 160, align: 'left' },
    { field: "Total", title: '总票数', rowspan: 2, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "", title: '服务态度', colspan: 3, sortable: false, width: 150, align: 'center' },
    { field: "", title: '办事效率', colspan: 3, sortable: false, width: 150, align: 'center' },
    { field: "", title: '深入现场', colspan: 3, sortable: false, width: 150, align: 'center' },
    { field: "", title: '首问负责', colspan: 3, sortable: false, width: 150, align: 'center' },
    { field: "", title: '廉洁自律', colspan: 3, sortable: false, width: 150, align: 'center' },
    { field: "", title: '综合评价', colspan: 3, sortable: false, width: 150, align: 'center' }
],
[
    { field: "Result_1_1", title: result_name_1, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_1_2", title: result_name_2, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_1_3", title: result_name_3, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_2_1", title: result_name_1, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_2_2", title: result_name_2, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_2_3", title: result_name_3, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_3_1", title: result_name_1, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_3_2", title: result_name_2, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_3_3", title: result_name_3, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_4_1", title: result_name_1, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_4_2", title: result_name_2, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_4_3", title: result_name_3, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_5_1", title: result_name_1, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_5_2", title: result_name_2, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_5_3", title: result_name_3, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_6_1", title: result_name_1, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_6_2", title: result_name_2, sortable: false, width: 50, align: 'center', formatter: resultFormatter },
    { field: "Result_6_3", title: result_name_3, sortable: false, width: 50, align: 'center', formatter: resultFormatter }
]
];

function resultFormatter(val, row) {
    if (val == "0") {
        return "<span style='color:#ccc;'>0</span>";
    } else {
        return "<span style='color:#085fa6;'>" + val + "</span>";
    }
}

$(document).ready(function () {
    //导出
    $("#btnexport").click(function (evt) {
        evt.preventDefault();

        exportFile();
    });
    
    $("#btnselectyear").click(function (evt) {
        evt.preventDefault();
        dlg.setSize(700, 460);
        dlg.setURL("选择测评年度", baseurl + "Public/EvalSelect?callback=onEvalSelected");
        dlg.show();
    })

    LoadDatagrid();
});

function onEvalSelected(data) {
    var json = JSON.parse(data);
    location.href = baseurl + "Report/OfficeResult/Summary/" + json.EvaluateYear;
}

//加载列表数据
function LoadDatagrid() {
    var $dg = $("#datagrid");
    $dg.treegrid({
        title: '',
        url: baseurl + 'Report/OfficeResult/SummaryReportResultJson',
        fit: true,
        fitColumns: false,
        animate: true,
        striped: true,
        nowrap: true,
        lines: false,
        idField: 'id',
        treeField: 'text',
        //pagination: false,
        //pageNumber: 1,
        //pageSize: 20,
        //pageList: [10, 20, 30, 45, 60, 75],
        //rownumbers: true,
        singleSelect: true,
        queryParams: {
            evalId: $("#evalId").val()
        },
        //sortName: 'Sort',
        //sortOrder: 'asc',
        columns: cols,
        onLoadSuccess: function () {
            //多选时，加载完成后清除所有选中项（不然可能会有残留选中项）
            $dg.datagrid("clearSelections");
        },
        rowStyler: function (row) {
            if (colorMap[row.Eval_dept_id]) {
                return "background-color:" + colorMap[row.Eval_dept_id];
            }
        }
    });
}

//导出
function exportFile() {
    var sort = $("#datagrid").datagrid('options').sortName;
    var order = $("#datagrid").datagrid('options').sortOrder;
    layer.msg("正在生成文件，请稍后...", { icon: 16, time: 0 });
    $.ajax({
        type: "post",
        url: baseurl + "Report/OfficeResult/CreateSummaryExportFile",
        dataType: 'json',
        data: {
            evalId: $("#evalId").val(),
            sort: sort,
            order: order
        },
        success: function (e) {
            layer.closeAll();
            if (e.Ret == "0") {
                location.href = baseurl + "Report/OfficeResult/DownFile?key=" + e.Content;
            } else {
                $.messager.alert("错误", e.Msg, "error");
            }
        },
        error: function (xhr) {
            showError(xhr);
        }
    });
}